<template>
	<view class="content">
		<u-toast ref="uToast"></u-toast>
		<image style="width: 300rpx;height: 150rpx;padding: 80rpx;" src="../../static/imager/login/loger-re.png"></image>
		<view class="content-login">
			<view>
				<!-- <button type="primary" open-type="getPhoneNumber" @click="getPhoneNumber"></button> -->
				<button  class="login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快速登录</button>
			</view>	
			<!-- <view class="checkbox">
				<u-checkbox-group @change="checkboxChange" v-model="privacy" placement="row">
					<u-checkbox activeColor="blue"  shape="circle"></u-checkbox>
					<span class="privacy-text">已阅读并同意 《隐私协议》</a></span>
				</u-checkbox-group>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		loginUser
	} from '@/api/user.js';
	export default {
		data() {
			return {
				title: 'Hello',
				privacy:"",
				code:"",
				appid:"wxa7202314d4922691",
				secret:"9ea5ec99dc290173e1a43b4ae9ba171b",
				check:false,
			}
		},
		onLoad:function(){
			
		},
		methods: {
			  getPhoneNumber (e) {
				  // if(!this.check){
					 //  uni.showToast({
					 //  	title: '请先同意隐私政策',
					 //  	icon: 'none',
					 //  	duration: 1688,
					 //  })
					 //  return;
				  // }
				   if (e.detail.errMsg == "getPhoneNumber:ok") {
						  uni.showLoading({
						  	title: '登录中'
						  })
						  loginUser({
						  		code:e.detail.code
						  	}).then((res) => {
						  		if (res.data.code == '0') {
									console.log(res)
									console.log(res.data.phone);
									uni.setStorageSync('token', res.data.token.token);
						  			uni.showToast({
						  				title: '登录成功!',
						  				icon: 'none',
						  				duration: 1688,
						  			})
						  			if(that.checked){
						  				//uni.setStorageSync("checked",that.checked);
						  				//uni.setStorageSync('userNamePwd',{userName:that.username,pwd:that.password})
						  			}else{
						  				//uni.setStorageSync("checked",false);
						  				//uni.removeStorageSync("userNamePwd");
						  			}
						  			setTimeout(() => {
						  				uni.reLaunch({
						  					url: '../index/index'
						  				})
						  			}, 888)
						  			var _data = res.data;
						  			
						  		
						  		} else {
						  			uni.showToast({
						  				title: '登录失败请稍后尝试!',
						  				icon: 'none',
						  				duration: 1688,
						  			})
						  			
						  		}
						  		}).catch(err => {
									uni.showToast({
										title: '登录失败请稍后尝试!',
										icon: 'none',
										duration: 1688,
									})
						  			this.loading = false;
						  			this.loadTitle = '加载更多'; 
						  		})
					  }else{
						  this.$refs.uToast.show({
						      type: "default",
						      message: "用户已取消",
						  });
					  }
			  },
			login(){
				uni.showLoading({
					title: '登录中...'
				})
				let reqData = {
					action: 'login',
				}
			loginUser({
					code:"111"
				}).then((res,resDate) => {
					console.log("sss")
					console.log(res)
					if (res.data.code == '0') {
						uni.showToast({
							title: '登录成功!',
							icon: 'none',
							duration: 1688,
						})
						if(that.checked){
							//uni.setStorageSync("checked",that.checked);
							//uni.setStorageSync('userNamePwd',{userName:that.username,pwd:that.password})
						}else{
							//uni.setStorageSync("checked",false);
							//uni.removeStorageSync("userNamePwd");
						}
						setTimeout(() => {
							uni.reLaunch({
								url: '../index/index'
							})
						}, 888)
						var _data = res.data;
						
					
					} else {
						//helper.msg(res.data.msg);
						
					}
					}).catch(err => {
						this.loading = false;
						this.loadTitle = '加载更多'; 
					})
				// if(this.privacy.length===0){
				// 	this.$refs.uToast.show({
				// 		type: "default",
				// 		message: "请先同意《第三方...》"
				// 	});
				// 	return;
				// }else{
				
				// }
			},
			checkboxChange(n) {
				this.check=n;
				console.log('change', n);
			}
		}
	}
</script>

<style>
	a{
		text-decoration: none;
		color:royalblue;
	}
	.login-btn{
		border-radius: 35px;
		background-color: blue;
		color: white;
		padding:30rpx;
		font-size: 30rpx;
	}
	.content{
		text-align: center;
	}
	.content-login{
		padding: 60rpx 30rpx;
	}
	.privacy-text{
		color:gray;
		font-size: 16rpx;
	}
	.checkbox{
		padding-top: 30rpx;
		height: 28rpx;
		line-height: 28rpx;
	}
</style>
